package cn.xianyang._05sync;


import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.io.UnsupportedEncodingException;

public class Producer {
    public static void main(String[] args) throws UnsupportedEncodingException, MQClientException, RemotingException, InterruptedException, MQBrokerException {
        //1.创建生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("hello_group_producer");
        //2.设置NameServer的地址,连接mq
        producer.setNamesrvAddr("127.0.0.1:9876");
        //3.启动生产者
        producer.start();
        //4.消息准备
        Message msg = new Message("hello_topic_Test", "hello_tags_Test", ("Hello RocketMQ!!!").getBytes(RemotingHelper.DEFAULT_CHARSET));

        //5.消息发送
        SendResult send = producer.send(msg);
        System.out.println(send);
        //6.关闭生产者
        producer.shutdown();
    }
}
